package org.yty.travelagencymongodb.controller;

import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.yty.travelagencymongodb.model.Entity.Order;
import org.yty.travelagencymongodb.model.Entity.Result;
import org.yty.travelagencymongodb.service.OrderService;

@RestController
@RequestMapping("/order")
@RequiredArgsConstructor
public class OrderController {
    private final OrderService orderService;

    @GetMapping("/{id}")
    public Result<Order> getOrderById(@PathVariable Long id) {
        Order result = orderService.getById(id);
        if (result == null) {
            return Result.error("订单不存在");
        } else {
            return Result.ok(result);
        }
    }

    @DeleteMapping("/{id}")
    public Result<Void> deleteOrderById(@PathVariable Long id) {
        orderService.removeById(id);
        return Result.ok();
    }
}
